<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">服务类型:</label>
            <div class="layui-input-block" lay-verify="required">
                <select name="type">
                    <option value="">请选择一个服务类型</option>
                    <option value="0">MQTT</option>
                    <option value="1">REST</option>
                    <option value="2">NATS</option>
                    <option value="3">AMQP</option>
                    <option value="4">CoAP</option>
                    <option value="5">XMPP</option>
                    <option value="6">DDS</option>
                 </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">服务器地址:</label>
            <div class="layui-input-block">
                <input type="text" name="host" lay-verify="host" value="" lay-reqtext="服务器IP不能为空" placeholder="请输入服务器域名或IP地址" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">端口:</label>
            <div class="layui-input-block">
                <input type="text" name="port" lay-verify="required" lay-reqtext="端口不能为空" placeholder="请输入端口" value="" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item">
            <label class="layui-form-label required">扩展参数:</label>
            <div class="layui-input-block">
                <input type="text" name="subject" lay-verify="required" lay-reqtext="扩展参数不能为空" value="" placeholder="请输入扩展参数" class="layui-input">
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名:</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label required">密码:</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" class="layui-input" lay-reqtext="密码不能为空" placeholder="请输入密码">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述:</label>
            <div class="layui-input-block">
                <textarea name="desc" class="layui-textarea" placeholder="请输入描述"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function() {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        form.render();
        var parentIndex = layer.index;
        form.verify({
            host: function(value, item) {
                function isValidIP(ip) {
                    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
                    return reg.test(ip);
                }
                if (isValidIP(value) == false) {
                    return '请输入正确的IP地址';
                }
            }
        });
        form.on('submit(saveBtn)', function(data) {
            var field = data.field;
            layer.msg("添加成功", {
                icon: 1
            });
            layer.close(parentIndex);
            return false;
        });

    });
</script>